package com.v5.mr.totalsalary;
import java.io.IOException;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
//                                                                k2 部门号     v2 员工对象
public class TotalSalaryMapper extends Mapper<LongWritable, Text, LongWritable, Employee> {

	@Override
	protected void map(LongWritable key1, Text value1, Context context)
			throws IOException, InterruptedException {
		// 数据：7654,MARTIN,SALESMAN,7698,1981/9/28,1250,1400,30
		String data = value1.toString();
		
		//分词
		String[] words = data.split(",");
		
		//创建一个员工对象
		Employee e = new Employee();
		
		//设置员工号
		e.setEmpno(Integer.parseInt(words[0]));
		//设置姓名
		e.setEname(words[1]);
		
		//设置职位 job
		e.setJob(words[2]);
		
		//设置老板号
		try{
			e.setMgr(Integer.parseInt(words[3]));
		}catch(Exception ex){
			//老板号为null
			e.setMgr(0);
		}
		
		//设置入职日期
		e.setHiredate(words[4]);
		
		//设置薪水
		e.setSal(Integer.parseInt(words[5]));
		
		//设置奖金
		try{
			e.setComm(Integer.parseInt(words[6]));
		}catch(Exception ex){
			//没有奖金
			e.setComm(0);
		}
		
		//设置部门号
		e.setDeptno(Integer.parseInt(words[7]));
		
		
		//输出
		context.write(new LongWritable(e.getDeptno()), e);
	}
}











